#ifndef VIEWMANAGER_H
#define VIEWMANAGER_H

#include <QWidget>
#include <QLabel>
#include <QSplitter>
#include <QStackedLayout>
#include <QLayout>
#include <QHBoxLayout>
#include <QMouseEvent>

#include <pageandview/pagewidget.h>
#include <pageandview/viewwidget.h>
#include <pageandview/common.h>

class PageWidget;
class ViewWidget;

class ViewManager : public QWidget
{
    Q_OBJECT
public:
    explicit ViewManager(QWidget *parent = 0, PageWidget *page = 0, IPluginGadget * pluginconfig = 0);
    ~ViewManager();

    inline ViewWidget *view() const {return m_view;}
    inline bool isSplitter() const {return m_splitter != 0;;}

    ViewManager* findViewManager(IPluginGadget *pluginconfig);
    ViewManager* findViewManager(ViewWidget *view);
    ViewManager* findViewManager(ViewManager *child);

    ViewManager* findFirstView();

    void split(Qt::Orientation orientation, bool restoring);
    void unsplit(ViewManager *child2remove);

    QSplitter *takeSplitter();
    ViewWidget *takeView();

    void saveSettings(QSettings* qs = 0);
    void readSettings(QSettings* qs = 0);

signals:

public slots:

private:
    PageWidget * m_pagewidget;
    ViewWidget * m_view;
    QSplitter * m_splitter;
    // Our layout, we use stacked so we can change stuff without visual artifacts (I think...)
    QHBoxLayout *m_layout;
    // The splitter sizes. We keep our own copy of these, since after loading they can't realiably be retrieved.
    QList<int> m_sizes;


protected:
    void mousePressEvent(QMouseEvent *e);

};

#endif // VIEWMANAGER_H
